package com.google.code.jcooky.chat.server.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class XProperties extends Properties {
	
	
	private static XProperties instance = null;
	
	private XProperties() {
		super();
		
		if(Arguments.CONFIG_FILE != null) {
			try {
				loadFromXML(new FileInputStream(Arguments.CONFIG_FILE));
			} catch (FileNotFoundException e) {
				throw new RuntimeException(e);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
	}
	
	public static int getInt(String key) {
		return Integer.parseInt(getInstance().getProperty(key));
	}
	
	public static String getString(String key) {
		return getInstance().getProperty(key);
	}
	
	public static void add(String key, String value) {
		getInstance().put(key, value);
	}
	
	private static XProperties getInstance() {
		if(instance == null) {
			synchronized(XProperties.class) {
				if(instance == null) {
					instance = new XProperties();
				}
			}
		}
		
		return instance;
	}
}
